<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>主订单列表</title>
    <script src="js/axios.min.js"></script>
    <script src="js/vue.min.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="ele-2.15.7/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="ele-2.15.7/index.js"></script>
</head>

<style>

    .box-card {
        width: 100%;
        height: 200px;
        margin: auto;
        margin-top:30px ;
    }

    .container-filter{
        height: 140px;
    }

    .operate-container{
        height: 60px;
        margin-bottom:20px;
    }




</style>

<body>
<div id="app">
    <div class="main-container">

        <div class="el-card box-card container-filter">
            <div class="el-card__body">
                <div>
                    <div class="search-top ">
                        <i class="el-icon-search"></i>
                        <span> 筛选搜索</span>
                        <el-button style="float: right;font-size: 12px" class="el-button--primary" @click="query(1)">查询结果</el-button>
                        <el-button style="float: right;font-size: 12px; margin-right: 15px" @click="resetInput">重置</el-button>
                    </div>
                    </button>
                </div>
            </div>

            <div style="margin-top: 15px;">
                <el-form :inline="true"  class="demo-form-inline" style="margin-left: 20px">
                    <el-form-item label="输入搜索:">
                        <el-input v-model="orderid" placeholder="订单编号"></el-input>
                    </el-form-item>
                    <el-form-item label="收货人:">
                        <el-input v-model="receivername" placeholder="收货人"></el-input>
                    </el-form-item>
                    <el-form-item label="订单状态:">
                        <el-select v-model="status" placeholder="全部">
                            <el-option
                                    v-for="item in statusOption"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="创建时间:">
                        <el-col :span="35">
                            <el-date-picker type="date" placeholder="选择日期" v-model="createtime" style="width: 100%;"></el-date-picker>
                        </el-col>
                    </el-form-item>
                </el-form>
            </div>

        </div>

        <el-card class="box-card operate-container box-card " shadow="never">
            <i class="el-icon-tickets"></i>
            <span>数据列表</span>
        </el-card>

        <div class="table-container box-card">
            <el-table :header-cell-style="{'text-align':'center'}"  :cell-style="{'text-align':'center'}" border  :data="tableData.data" style="width: 100%" >
                <el-table-column fixed prop="orderid" label="订单编号" width="90"></el-table-column>
                <el-table-column prop="createtime" label="创建时间"width="240" >
                    <template slot-scope="{ row }">
                        {{ row.createtime | formatTimer }}
                    </template>
                </el-table-column>
                <el-table-column prop="uname" label="下单的人"width="160" ></el-table-column>
                <el-table-column prop="receivername" label="收货人"width="160" ></el-table-column>
                <el-table-column prop="totalprice" label="订单金额" width="180">
                    <template slot-scope="scope">
                        <span>{{scope.row.totalprice}}元</span>
                    </template>
                </el-table-column>
                <el-table-column prop="paymenttype" label="支付方式" width="150"></el-table-column>
                <el-table-column prop="status" label="订单状态" width="144" >
                    <template slot-scope="scope">
                        <span v-if="scope.row.status=='0'">已取消</span>
                        <span v-else-if="scope.row.status==10">未付款</span>
                        <span v-else-if="scope.row.status==20">待发货</span>
                        <span v-else-if="scope.row.status==30">已发货</span>
                        <span v-else-if="scope.row.status==40">交易成功</span>
                        <span v-else-if="scope.row.status == '50'">已付款</span>
                    </template>
                </el-table-column>
                <el-table-column  label="操作" >
                    <template slot-scope="scope">
                        <el-button
                                size="mini"
                                @click="modify(scope.row)">查看订单
                        </el-button>

                        <el-button
                                size="mini"
                                type="button"
                                type="button"
                                @click="remove(scope.row)">
                            <span v-if="scope.row.status==0">删除订单</span>
                            <span v-if="scope.row.status==10">关闭订单</span>
                            <span v-if="scope.row.status==20">订单发货</span>
                            <span v-if="scope.row.status==30">订单跟踪</span>
                            <span v-if="scope.row.status==40">订单跟踪</span>
                        </el-button>

                    </template>
                    
                </el-table-column>

            </el-table>
            <el-footer style="text-align: right">
                <el-pagination :page-size="pageSize" @current-change="query" @size-change="sizeChange"
                               background :page-sizes="[10,15,20]"
                               layout="total,sizes,prev, pager,next,jumper"
                               :total="tableData.total"
                               :current-page.sync="tableData.page">
                </el-pagination>
            </el-footer>
        </div>
    </div>
</div>

<script>
    var v = new Vue({
        el : "#app",
        data : {
            // tableData: [],
            receivername : "",
            orderid : "",
            pageSize: 10,
            createtime :"",
            status: "",
            statusOption : [{
                label: "已取消",
                value: "0"
            },{
                label: "待付款",
                value: "10"
            },{
                label: "待发货",
                value: "20"
            },{
                label: "已发货",
                value: "30"
            },{
                label: "交易成功",
                value: "40"
            }],
            //表格数据
            tableData: {page:1}
        },
        created() {
            this.query(1);
        },
        methods : {
            query(page) {
                axios.get("OrderListServlet.s",{
                    params: {
                        orderid : this.orderid,
                        receivername : this.receivername,
                        createtime : this.formdate(this.createtime),
                        status : this.status,
                        currentPage : page, //当前页数
                        pageSize: this.pageSize //每页显示条目个数
                    }
                }).then(res=>{
                    this.tableData = res.data;
                    this.tableData.page = page;
                })
            },

            sizeChange(page){
                this.pageSize =page;
                this.query(1);
            },
            //查询框重置
            resetInput(){
                this.receivername = "";
                this.orderid = "";
                this.createtime = "";
                this.status = ""
            },

            //修改订单状态
            modify(data){

            },
            formdate(value) {
                if (value!=""){
                    let date = new Date(value);
                    let y = date.getFullYear();
                    let MM = date.getMonth() + 1;
                    MM = MM < 10 ? "0" + MM : MM;
                    let d = date.getDate();
                    d = d < 10 ? "0" + d : d;
                    let h = date.getHours();
                    h = h < 10 ? "0" + h : h;
                    let m = date.getMinutes();
                    m = m < 10 ? "0" + m : m;
                    let s = date.getSeconds();
                    s = s < 10 ? "0" + s : s;
                    console.info(y + "-" + MM + "-" + d + " " + h + ":" + m);
                    return this.createtime =y + "-" + MM + "-" + d;
                }else {
                    return this.createtime ="";
                }
            },

        },


        filters: {
            formatTimer: function(value) {
                let date = new Date(value);
                let y = date.getFullYear();
                let MM = date.getMonth() + 1;
                MM = MM < 10 ? "0" + MM : MM;
                let d = date.getDate();
                d = d < 10 ? "0" + d : d;
                let h = date.getHours();
                h = h < 10 ? "0" + h : h;
                let m = date.getMinutes();
                m = m < 10 ? "0" + m : m;
                let s = date.getSeconds();
                s = s < 10 ? "0" + s : s;
                return y + "-" + MM + "-" + d + " " + h + ":" + m;
            }
        },
    })
</script>

</body>
</html>